package com.hongruan.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.hongruan.bean.zdybd.WSZLLZHZD;
import com.hongruan.dao.ReportWstjDao;

@Repository
public class ReportWstjDaoImpl extends GenericDaoHibernateImpl<WSZLLZHZD, Long> implements ReportWstjDao {

	public ReportWstjDaoImpl(){
		super(WSZLLZHZD.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<WSZLLZHZD> getWstjList(String slrq,int page,int pagesize,long swjgUuid,String sort1,String sort2) {
		String hql = "from WSZLLZHZD where slsj = :slrq and swjgUuid = :swjgUuid";
		Query query = null;
		if(124 == swjgUuid){
			hql = "from WSZLLZHZD where slsj = :slrq order by swjgUuid";
			query = this.getCurrentSession().createQuery(hql);
			query.setString("slrq", slrq);
		}else{
			if("all".equals(sort1)){
				hql = "from WSZLLZHZD where slsj = :slrq and swjgUuid = :swjgUuid order by :sort2";
			}else{
				hql = "from WSZLLZHZD where slsj = :slrq and swjgUuid = :swjgUuid and cbbm = :sort1 order by :sort2";
			}
			query = this.getCurrentSession().createQuery(hql);
			query.setString("slrq", slrq);
			query.setLong("swjgUuid", swjgUuid);
			query.setString("sort2", sort2);
			if(!"all".equals(sort1)){
				query.setString("sort1", sort1);
			}

		}
		
		return query.list();
	}

	public int getTotal(String slrq){
		String hql = "select count(*) from WSZLLZHZD where slsj = :slrq";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setString("slrq", slrq);
		return 0;
	}
	
	@SuppressWarnings("unchecked")
	public List getCbbmList(long swjgUuid) {
		Query query = null;
		String hql = "select distinct cbbm from t_zdybd_wszllzhzd where swjgUuid = :swjgUuid";
		if(124 == swjgUuid){
			hql = "select distinct cbbm from t_zdybd_wszllzhzd";
			query = this.getCurrentSession().createSQLQuery(hql);
		}else{
			query = this.getCurrentSession().createSQLQuery(hql);
			query.setLong("swjgUuid", swjgUuid);
		}
		return query.list();
	}
}
